//
//  EmoticonAttachment.swift
//  表情键盘
//
//  Created by 吴婷婷 on 15/11/15.
//  Copyright © 2015年 wutingting. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {
    var emoticon: Emoticon
    /// 将当前附件中的 emoticon 转换成属性文本
    func imageText (font: UIFont)-> NSAttributedString{
        //1>创建图像附件
        image = UIImage(contentsOfFile: emoticon.imagePath)
        
        //线高改图片高度
        let lineHeight = font.lineHeight
        bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        //设置图片的字体
        return imageText
    }
    
    //MARK: - 构造函数
    init(emoticon: Emoticon) {
        self.emoticon = emoticon
        
        super.init(data: nil, ofType: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
